{layout name="layout"}
<div class="panel">
    <div class="panel-heading bg-gray-light">
        <h3 class="panel-title text-dark" style="flo">{$project.classifyname}</h3>
    </div>
    <div class="panel-body">
        <div class="pad-btm form-inline">
            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button id="node-btn-addrow" data-target="#categories-modal" data-toggle="modal" class="btn btn-default" data-catid="{$project.id}"><i class="fa fa-plus-circle"></i> 添加分类</button>
                </div>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-striped">
            <colgroup>
                <col width="20%">
                <col width="40%">
                <col width="20%">
                <col width="20%">
            </colgroup>
                <thead>
                    <tr>
                        <th class="text-center">分类名称</th>
                        <th class="text-center">分类描述</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                </thead>
                <tbody>
                {if $categories}
                {foreach $categories as $category}
                    <tr>
                        <td class="text-center">{$category.classifyname}</td>
                        <td class="text-center">{$category.description}</td>
                        <td class="text-center">{$category.addtime}</td>
                        <td class="text-center">
                            <button class="btn btn-default" data-target="#categories-modal" data-toggle="modal" data-catid="{$category.id}"><i class="fa fa-pencil-square-o"></i></button>
                            <button class="btn btn-default" onclick='del_project(this,"{$category.id}")'><i class="ion-trash-b"></i></button>
                        </td>
                    </tr>
                {/foreach}
                {/if}
                </tbody>
            </table>
        </div>
    </div>
</div>
{include file="modals/categories-modal"}
<script type="text/javascript">
    function del_project(e,catid){
        bootbox.setDefaults({locale:"zh_CN"});
        bootbox.confirm("确定删除吗", function(result) {
            if(result){
                $.ajax({
                    url:"{:url('api/projects/del_cat')}",
                    type:"post",
                    data:{"catid":catid},
                    dataType:"json",
                    success:function(result){
                        if(result.status == 'success'){
                            $.niftyNoty({
                                type: 'success',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                            $(e).parents('tr').detach();
                        }else{
                            $.niftyNoty({
                                type: 'warning',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                        }
                    },
                    error:function(){
                        $.niftyNoty({
                            type: 'danger',
                            icon : 'pli-exclamation icon-2x',
                            message : '网络连接失败',
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                });
            }
        })
        
    }
</script>